/**
 * Created by superman on 17/2/16.
 * http配置
 */
import Vue from 'vue'
import axios from 'axios'
import router from '../router'

// axios 配置
axios.defaults.timeout = 5000;
axios.defaults.baseURL = 'http://bill.mydreams.xin/bill';
// axios.defaults.baseURL = 'http://127.0.0.1:8088';
// axios.defaults.baseURL = '/bill';
axios.defaults.withCredentials = true;
axios.defaults.timeout =  60000;

// axios.defaults.headers.post['content-Type'] = 'Access-Control-Allow-Origin';

// http request 拦截器
axios.interceptors.request.use(
	config => {
		return config;
	},
	err => {
		return Promise.reject(err);
	});

// http response 拦截器
axios.interceptors.response.use(
	response => {
		switch(response.data.code) {
			case 1205:
				router.replace({
					name: 'login',
					query: {
						redirect: router.currentRoute.name
					}
				})
				break;
			case 403:
				router.replace({
					path: '/forbidden'
				})
				break;
		}
		return response;
	},
	error => {
		return Promise.reject(error.response.data)
	});

export default axios;